# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=pupnp
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=1.6.25
pkgrel=1
pkgdesc="Portable SDK for UPnP* Devices (mingw-w64)"
arch=('any')
url="http://pupnp.sourceforge.net/"
license=("BSD")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc" "${MINGW_PACKAGE_PREFIX}-pkg-config")
options=('strip' 'staticlibs')
source=(${_realname}-${pkgver}.tar.gz::https://github.com/mrjimenez/pupnp/archive/release-${pkgver}.tar.gz
        001-libupnp-win64.patch
        002-libupnp-win32.patch
        003-no-undefined.patch
        004-win32-dll.patch
        )
sha256sums=('a7b746064b799e412e25d3e10a3b157620b427e7244e4a66bc0984bd5a4a6d20'
            '69d20cbfdf0cd0017404d9b5262dad2370fb55749063578659e77dc1606c0ded'
            'da9a1adf5d01bab81f50399b114ff42a3ea92f61adc5b98e8085b561f0937ca8'
            '863f2732602fd1e504d8ed664ac1f588fd6f28adaac33c3fa0899fd9038216d8'
            'c2a480949e3a2184b2f82a80cc32b396989f5ae781a65897e231a0063a72092d')

prepare() {
  cd "${srcdir}/${_realname}-release-${pkgver}"
  patch -p1 -i ${srcdir}/001-libupnp-win64.patch
  patch -p1 -i ${srcdir}/002-libupnp-win32.patch
  patch -p1 -i ${srcdir}/003-no-undefined.patch
  patch -p1 -i ${srcdir}/004-win32-dll.patch

  autoreconf -fi
}

build() {
  [[ -d ${srcdir}/build-${MINGW_CHOST} ]] && rm -rf ${srcdir}/build-${MINGW_CHOST}
  mkdir -p ${srcdir}/build-${MINGW_CHOST} && cd ${srcdir}/build-${MINGW_CHOST}

  ../${_realname}-release-${pkgver}/configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST} \
    --enable-static \
    --enable-shared \
    --enable-ipv6

  make
}

package() {
  cd build-${MINGW_CHOST}
  make DESTDIR="${pkgdir}" install

  install -Dm644 ${srcdir}/${_realname}-release-${pkgver}/COPYING ${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/COPYING
}
